package com.jy.wms.service;


import com.jy.wms.common.UUIDUtils;
import com.jy.wms.common.annotions.BaseServiceDescribe;
import com.jy.wms.common.base.BaseService;
import com.jy.wms.common.base.InterfaceCall;
import com.jy.wms.common.base.ServiceException;
import com.jy.wms.common.base.SucessException;
import com.jy.wms.dao.*;
import com.jy.wms.pojo.*;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.text.SimpleDateFormat;
import java.util.*;

/**
 * @ClassName: UserController
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @Author syh
 * @Date 2018/9/13
 */
@Service
public class OrderInterfaceService extends BaseService<OrderInterfaceMapper, WmsShipmentOrderDetailed> {
    protected static Logger log = Logger.getLogger(WmsPickingService.class);
    SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    @Autowired
    WmsShipmentOrderMapper wmsShipmentOrderMapper;
    @Autowired
    WmsShipmentOrderDetailedMapper wmsShipmentOrderDetailedMapper;
    @Autowired
    WmsOwnerOrdertypeMapper wmsOwnerOrdertypeMapper;
    @Autowired
    WmsBiztypeMapper wmsBiztypeMapper;
    @Autowired
    WmsTranstypeMapper wmsTranstypeMapper;
    @Autowired
    YofotoMapper yofotoMapper;
    @Autowired
    WmsTypeMapper wmsTypeMapper;

    /**
     * 其他出库单生成接口
     *
     * @param fymxids          发运明细集合
     * @param wmsShipmentOrder 发运订单
     */
    @BaseServiceDescribe(moduleName = "其他出库单生成接口", btnName = "传参数给其他出库单接口")
    public JSONObject otherOrder(List<String> fymxids, WmsShipmentOrder wmsShipmentOrder) throws Exception {

        //一条发运订单对应多条明细，一条发运明细会对应多条拣货记录
        JSONArray detailjsons = new JSONArray();//单据明细集合
        int i = 0;
        //订单类型
        WmsOwnerOrdertype wmsOwnerOrdertype= wmsOwnerOrdertypeMapper.baseSelectByPrimaryKey(wmsShipmentOrder.getFylx());
        WmsShipmentOrder wmsShipmentOrder1=dao.getType(wmsShipmentOrder.getId());
       /*WmsBiztype wmsBiztype=wmsBiztypeMapper.baseSelectByPrimaryKey(wmsShipmentOrder.getBiztype());
        WmsTranstype wmsTranstype= wmsTranstypeMapper.baseSelectByPrimaryKey(wmsShipmentOrder.getTranstype());*/
        for (String fymxid : fymxids) {
            List<WmsShipmentOrderDetailed> detailedList = dao.detailList(fymxid);//一条发运明细对应的多条拣货记录
            for (WmsShipmentOrderDetailed wmsShipmentOrderDetailed : detailedList) {
                i = i + 1;
                JSONObject detailjson = new JSONObject();//单据明细
                detailjson.put("sono", wmsShipmentOrder.getFybh());//出库单号
                detailjson.put("lineno", i);//行号
                detailjson.put("sotype", wmsOwnerOrdertype.getLxdm());//订单类型
                detailjson.put("matno", wmsShipmentOrderDetailed.getBh());//货品编号
                detailjson.put("qcstatus", wmsShipmentOrderDetailed.getShow_zjzt());//质检状态
                detailjson.put("batch", wmsShipmentOrderDetailed.getHppc());//货品批次
                detailjson.put("quant", Double.parseDouble(wmsShipmentOrderDetailed.getYqsl()));//预期数量
                detailjson.put("bkquant",Double.parseDouble(wmsShipmentOrderDetailed.getSjsl()));//发运数量
                detailjsons.add(detailjson);
            }
        }
        JSONObject headJson = new JSONObject();//单据头
        headJson.put("sono", wmsShipmentOrder.getFybh());//出库单号
        headJson.put("bilno", "");//收货单号
        headJson.put("sotype", wmsOwnerOrdertype.getLxdm());//订单类型
      /*  headJson.put("biztype", wmsShipmentOrder.getBiztype());//业务类型
        headJson.put("tasktype", wmsShipmentOrder.getTranstype());//事物类型
        headJson.put("whouse", wmsShipmentOrder.getCkid());//仓库
        headJson.put("works", wmsShipmentOrder.getSshzid());//货主*/
        headJson.put("biztype", wmsShipmentOrder1.getBiztype());//业务类型
        headJson.put("tasktype", wmsShipmentOrder1.getTranstype());//事物类型
        headJson.put("whouse", "SA01");//仓库
        headJson.put("works", "S.01");//货主
        headJson.put("custno", wmsShipmentOrder.getKhbh());//客户编号
        headJson.put("enddate", formatter.format(new Date()));//订单完成日期
        headJson.put("adminorg", "");//部门
        headJson.put("center", "");//成本中心
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("subhead", headJson);
        jsonObject.put("subdetail", detailjsons);
        JSONObject jb= InterfaceCall.allocation(jsonObject, "/easApi/getBackOtherIssueOrder");
        if(jb.get("backcode").toString().equals("-1")){
            throw new ServiceException("其他出库订单生成接口，"+jb.get("backmsg"));
        }
        return jb;

    }


    @BaseServiceDescribe(moduleName = "库存调拨单下发接口", btnName = "查看发运订单中是否有查询的发运订单")
    public WmsShipmentOrder getWmsShipment(Map map) {
        //获取该发运订单和发运类型对应的发运订单是否存在
        WmsShipmentOrder wmsShipmentOrder = dao.getOrderByBhAndLx(map);
        return wmsShipmentOrder;
    }

  /*  库存调拨单下发接口(获取返回的erp订单信息)*/


    @BaseServiceDescribe(moduleName = "erp订单信息查询接口", btnName = "获取返回erp订单信息（领料出库/调拨出库）")
    public WmsShipmentOrder getDBIssueOrder(WmsShipmentOrder entity, String cjr, JSONObject json) throws Exception {
        WmsShipmentOrder wmsShipmentOrder = new WmsShipmentOrder();
        Map headMap = new HashMap();
        List<Map> list = new ArrayList<>();
        if (entity.getSotype().equals("140")) {
            headMap = JSONObject.fromObject(json.get("head"));
            //wmsShipmentOrder.setSotype2("140");//判断是106调拨出库单则订单类型返回140
        } else if (entity.getSotype().equals("104")) {
            headMap = JSONObject.fromObject(json.get("backhead"));
        }
        if (headMap != null) {
            wmsShipmentOrder.setFybh(headMap.get("sono").toString());
            wmsShipmentOrder.setSotype(headMap.get("sotype").toString());
            if (headMap.get("sotype") != null) {
                WmsOwnerOrdertype wmsOwnerOrdertype = dao.getOrdertype(entity.getSotype());
                wmsShipmentOrder.setSotype(entity.getSotype());
                wmsShipmentOrder.setShow_fylx(wmsOwnerOrdertype.getDdlx());
                //单据类型
                wmsShipmentOrder.setBilltype(wmsOwnerOrdertype.getLxdm());
                //业务类型
             /*   if (entity.getBiztype() != null) {
                    List<WmsBiztype> wmsBiztypeList = wmsTypeMapper.ywType(entity.getSshzid(), entity.getCkid(), entity.getBiztype());
                    for (WmsBiztype wmsBiztype1 : wmsBiztypeList) {
                        wmsShipmentOrder.setBiztype(wmsBiztype1.getBh());
                        wmsShipmentOrder.setShow_biztype(wmsBiztype1.getMc());
                    }
                }*/
                //事物类型
               /* if (entity.getTranstype() != null) {
                    List<WmsTranstype> wmsTranstypeList = wmsTypeMapper.swType(entity.getSshzid(), entity.getCkid(), entity.getTranstype());
                    for (WmsTranstype wmsTranstype : wmsTranstypeList) {
                        wmsShipmentOrder.setTranstype(wmsTranstype.getBh());
                        wmsShipmentOrder.setShow_transtype(wmsTranstype.getMc());
                    }
                }*/
            }
            wmsShipmentOrder.setBz(headMap.get("description") == null ? "" : headMap.get("description").toString());
        }
        return wmsShipmentOrder;
    }

    @BaseServiceDescribe(moduleName = "erp订单信息接口", btnName = "新增发运订单")
    @Transactional
    public void InsertDBPoOrder(JSONObject jsonObject, WmsShipmentOrder entity) throws Exception {
        if (!"".equals(jsonObject.get("backcode")) && jsonObject.get("backcode") != null && jsonObject.get("backcode").toString().equals(-1)) {
            throw new ServiceException("获取erp订单信息失败");
        }
        //(head 为键的是库存调拨单下发接口)按head键取预期单对象
        JSONObject json = JSONObject.fromObject(jsonObject.get("head"));
        if(jsonObject.containsKey("head")){
            saveErpOrder(jsonObject, entity, json);
        }else{
            //backhead 为键的是领料出库单下发接口 按backhead键取预期单对象
            JSONObject jsons = JSONObject.fromObject(jsonObject.get("backhead"));
            if(jsonObject.containsKey("backhead")){
                saveErpOrder(jsonObject, entity, jsons);
            }
        }

    }

    /**
     * 提取,新增发运订单
     * @param jsonObject
     * @param wmsShipmentOrder
     * @param json
     * @return
     * @throws Exception
     */
    @Transactional
    @BaseServiceDescribe(moduleName = "库存调拨单/领料下发接口", btnName = "保存erp订单信息进入发运订单")
    public int saveErpOrder(JSONObject jsonObject, WmsShipmentOrder wmsShipmentOrder, JSONObject json) throws  Exception {
        wmsShipmentOrder.setId(UUIDUtils.uuid());
        //对方货主
        wmsShipmentOrder.setDfhzbh(String.valueOf(json.get("works")));
        //要求交货时间
        wmsShipmentOrder.setYqjhsj(String.valueOf(json.get("requireddate")));
        //发运编号
        wmsShipmentOrder.setFybh(String.valueOf(json.get("sono")));

        //业务类型
        /*if (wmsShipmentOrder.getBiztype() != null) {
            List<WmsBiztype> wmsBiztypeList = wmsTypeMapper.ywType(hzid, wmsShipmentOrder.getCkid(), wmsShipmentOrder.getBiztype());
            for (WmsBiztype wmsBiztype1 : wmsBiztypeList) {
                wmsShipmentOrder.setBiztype(wmsBiztype1.getId());
            }
        }*/
        //事物类型
       /* if (wmsShipmentOrder.getTranstype() != null) {
            List<WmsTranstype> wmsTranstypeList = wmsTypeMapper.swType(hzid, wmsShipmentOrder.getCkid(), wmsShipmentOrder.getTranstype());
            for (WmsTranstype wmsTranstype : wmsTranstypeList) {
                wmsShipmentOrder.setTranstype(wmsTranstype.getId());
            }
        }*/
        String ddlxid=dao.getDdlxs(String.valueOf(json.get("sotype")),wmsShipmentOrder.getCkid(),wmsShipmentOrder.getSshzid());
        wmsShipmentOrder.setFylx(ddlxid);
        wmsShipmentOrder.setKhcjsj(formatter.format(new Date()));
        wmsShipmentOrder.setKhddh(String.valueOf(json.get("sono")));
        wmsShipmentOrder.setCjsj(formatter.format(new Date()));
        //默认计划交货时间为当前时间
        wmsShipmentOrder.setJhfhsj(formatter.format(new Date()));
        wmsShipmentOrder.setCjr(wmsShipmentOrder.getCjr());
        wmsShipmentOrder.setYqjhsj(json.get("requireddate") == null ? formatter.format(new Date()) : String.valueOf(json.get("requireddate")));
        wmsShipmentOrder.setMdck(json.get("towhouse") == null ? "" : String.valueOf(json.get("towhouse")));
        //对方仓库
        wmsShipmentOrder.setDfckhb(json.get("whouse") == null ? "" : String.valueOf(json.get("whouse")));
        wmsShipmentOrder.setBz(json.get("description") == null ? "" : String.valueOf(json.get("description")));
        wmsShipmentOrder.setType(1);
        //区分提取还是创建
        wmsShipmentOrder.setAddlx(0);
        wmsShipmentOrder.setBack(json == null ? 0 : 1);
        wmsShipmentOrder.setBackmsg(jsonObject.get("backmsg").toString());
        //因领料而加的字段
        wmsShipmentOrder.setDdwcsj(json.get("enddate") == null ? "" : String.valueOf(json.get("enddate")));
        int a = dao.baseInsertSelectiveFz(wmsShipmentOrder);
        int b = 0;
        //按键detail 取明细集合(库存调拨单下发接口)
        List<Map<String, Object>> mapList = JSONArray.fromObject(jsonObject.get("detail"));
        //按键backdetail 取明细集合(领料出库单下发接口)
        List<Map<String, Object>> mapLists = JSONArray.fromObject(jsonObject.get("backdetail"));
        if (a > 0) {
            if(jsonObject.containsKey("detail") && mapList!=null){
                saveErpOrderMx(wmsShipmentOrder, mapList);
            }else{
                if(jsonObject.containsKey("backdetail") && mapLists!=null){
                    saveErpOrderMx(wmsShipmentOrder, mapLists);
                }
            }
            throw new SucessException("新增发运订单成功");
        } else {
            throw new SucessException("新增发运订单失败");
        }
    }

    /**
     * 提取,新增发运订单明细
     * @param wmsShipmentOrder
     * @param mapList
     * @throws Exception
     */
    @Transactional
    public void saveErpOrderMx(WmsShipmentOrder wmsShipmentOrder, List<Map<String, Object>> mapList) throws Exception{
        if (mapList.size() > 0) {
            WmsEstimatedArrivalOrderDetailed wmsdetailed = null;
            for (Map map : mapList) {
                WmsShipmentOrderDetailed wmsShipmentOrderDetailed = new WmsShipmentOrderDetailed();
                wmsShipmentOrderDetailed.setId(UUIDUtils.uuid());
                //8_21 新增  qcstatus质检状态(合格不合格)
                wmsShipmentOrderDetailed.setZjzt(String.valueOf(map.get("qcstatus")));
                // 预期数量 set的也是文档里的数量,先判断是否包含".",包含截取后set
                if(String.valueOf(map.get("quant")).indexOf(".")==-1){
                    String yqsl=String.valueOf(map.get("quant"));
                    wmsShipmentOrderDetailed.setYqsl(yqsl);
                }else {
                    //直接截取
                    String yqsl=String.valueOf(map.get("quant"));
                    String[] yqsls= yqsl.split(".");
                    wmsShipmentOrderDetailed.setYqsl(yqsls[0]);
                }
                //用map里的matno (商品编码) 去查产品id
                if(!"".equals(map.get("matno")) && map.get("matno")!=null){
                    List<WmsShipmentOrderDetailed> detailedList=dao.selectHpbm(String.valueOf(map.get("matno")));
                    if(detailedList!=null && detailedList.size()>0){
                        for(WmsShipmentOrderDetailed  orderDetailed:detailedList){
                            if(!"".equals(orderDetailed.getHpid()) && orderDetailed.getHpid()!=null){
                                if(orderDetailed.getBzlx().equals("0")){
                                    wmsShipmentOrderDetailed.setHpid(orderDetailed.getHpid());
                                    if(!"".equals(orderDetailed.getZdw()) && orderDetailed.getZdw()!=null){
                                        wmsShipmentOrderDetailed.setZdw(orderDetailed.getZdw());
                                    }else {
                                        wmsShipmentOrderDetailed.setZdw("");
                                    }
                                }
                                if(!"0".equals(wmsShipmentOrderDetailed.getYqsl()) && !"".equals(wmsShipmentOrderDetailed.getYqsl()) && wmsShipmentOrderDetailed.getYqsl()!=null) {
                                    if (orderDetailed.getBzlx().equals("2")) {
                                        if (!"0".equals(orderDetailed.getXzdwsl()) && !"".equals(orderDetailed.getXzdwsl()) && orderDetailed.getXzdwsl() != null) {
                                            //箱单位整数
                                            Integer xdwzs = Integer.parseInt(wmsShipmentOrderDetailed.getYqsl()) / Integer.parseInt(orderDetailed.getXzdwsl());
                                            //箱单位余数
                                            Integer xdwys = Integer.parseInt(wmsShipmentOrderDetailed.getYqsl()) % Integer.parseInt(orderDetailed.getXzdwsl());
                                            String yqxdwsl = xdwzs + "箱" + xdwys + "件";
                                            //箱件总数(xxx箱xx件)
                                            wmsShipmentOrderDetailed.setYqxdwsl(yqxdwsl);
                                        } else {
                                            wmsShipmentOrderDetailed.setYqxdwsl("0");
                                        }
                                    }
                                    //总金额
                                    if(orderDetailed.getBzlx().equals("0")){
                                        if(!"0".equals(orderDetailed.getJe()) && !"".equals(orderDetailed.getJe())){
                                            wmsShipmentOrderDetailed.setLsje(String.valueOf(Double.parseDouble(wmsShipmentOrderDetailed.getYqsl()) * orderDetailed.getJe()));
                                        }else{
                                            wmsShipmentOrderDetailed.setLsje("0");
                                        }
                                    }
                                }else{
                                    wmsShipmentOrderDetailed.setYqxdwsl("0");
                                    wmsShipmentOrderDetailed.setLsje("0");
                                }
                            }else {
                                throw new RuntimeException(String.valueOf(map.get("matno"))+"，此货品不存在");
                            }
                        }
                    }else{
                        throw new RuntimeException(String.valueOf(map.get("matno"))+"，此货品不存在");
                    }
                }else{
                    throw new RuntimeException(String.valueOf(map.get("matno"))+"，此货品不存在");
                }

                wmsShipmentOrderDetailed.setSsfyddid(wmsShipmentOrder.getId());
                wmsShipmentOrderDetailed.setPc(map.get("batch") == null ? "" : String.valueOf(map.get("batch")));
                wmsShipmentOrderDetailed.setCkid(wmsShipmentOrder.getCkid());
                wmsShipmentOrderDetailed.setCjsj(formatter.format(new Date()));
                //8_17新增行号
                wmsShipmentOrderDetailed.setHh(String.valueOf(map.get("lineno")));
                //8_20新增对方的调出仓库
                wmsShipmentOrderDetailed.setDfckhb(String.valueOf(map.get("whouse")));
                //目的仓库
                wmsShipmentOrderDetailed.setMdck(map.get("towhouse") == null ? "" : String.valueOf(map.get("towhouse")));
                //要求交货时间
                wmsShipmentOrderDetailed.setYqjhsj(map.get("requireddate") == null ? "" : String.valueOf(map.get("requireddate")));
                //备注
                wmsShipmentOrderDetailed.setMxbz(map.get("description") == null ? "" : String.valueOf(map.get("description")));
                int j = dao.baseInsertSelectiveMx(wmsShipmentOrderDetailed);
                if (j <= 0) {
                    throw new RuntimeException("新增发运订单明细失败");
                }
            }
        }
    }

    public WmsShipmentOrder getCountByfybh(String fybh) {
        return dao.getCountByfybh(fybh);
    }
    /////////////////新增保单接口///////////////////////////////

    /**
     * 查询发运订单对象(用对方提供的参数:订单号,货主)
     * @param sono
     * @param works
     * @return
     */
    public WmsShipmentOrder GetIssueOrderStatus(String sono,String works) throws Exception {
        return dao.GetIssueOrderStatus(sono, works);
    }

    /**
     * 查询订单对象以及拼接成json
     * @param shipmentOrder
     * @return
     * @throws Exception
     */
    public JSONObject GetIssueOrderStatusOrder (WmsShipmentOrder shipmentOrder) throws Exception {
        JSONObject jsonObject = new JSONObject();
        JSONObject headJson = new JSONObject();//单据头
        headJson.put("sono", shipmentOrder.getFybh());//出库单号
        headJson.put("whouse", shipmentOrder.getDfckhb());//仓库
        headJson.put("works", shipmentOrder.getDfhzbh());//货主
        if(shipmentOrder.getCdzt().equals("0") && shipmentOrder.getFyzt().equals("0")){
            headJson.put("sostatus","1");//1：未下发（未组建波次）拆单状态未拆的
        }else if(shipmentOrder.getFyzt().equals("3") || shipmentOrder.getFyzt().equals("4")){
            headJson.put("sostatus","3");//3.已发货（已与物流商交接）已发运
        }
        else if((shipmentOrder.getJhzt().equals("1") || shipmentOrder.getJhzt().equals("2")) || (shipmentOrder.getFyzt().equals("1") || shipmentOrder.getFyzt().equals("2")) || (shipmentOrder.getZxzt().equals("1") || shipmentOrder.getZxzt().equals("2")) || (shipmentOrder.getCdzt().equals("1"))){
            headJson.put("sostatus","2");//2：发货中 （波次已下发，拣货完成，复核完成）已拆单,已分配,已拣货,已装箱
        }
        if(shipmentOrder.getBz()!=null && !"".equals(shipmentOrder.getBz()) && !"null".equals(shipmentOrder.getBz())){
            headJson.put("description", shipmentOrder.getBz());//备注
        }else {
            headJson.put("description", "无");//备注
        }
        jsonObject.put("head", headJson);
        return jsonObject;
    }
    /**
     * 保存出库订单发修改方法
     * @param map
     * @throws Exception
     */
    @BaseServiceDescribe(moduleName = "出库订单的修改接口", btnName = "修改发运订单")
    @Transactional
    public void GetChangeIssueOrder(Map<String,Object> map) throws Exception {
        //按backhead键取发运订单
        Map<String,Object> map1=(Map<String,Object>)map.get("head");
        WmsShipmentOrder wmsShipmentOrder=dao.getCdzt(String.valueOf(map1.get("sono")),String.valueOf(map1.get("whouse")),String.valueOf(map1.get("works")));
        if(wmsShipmentOrder!=null) {
            if (("0").equals(wmsShipmentOrder.getCdzt())) {
                wmsShipmentOrder.setId(UUIDUtils.uuid());
                Integer li = dao.baseInsertEditFz(wmsShipmentOrder);
                if (li > 0) {
                    Map map2 = new HashMap();
                    map2.put("fybh", String.valueOf(map1.get("sono")));
                    map2.put("bz", String.valueOf(map1.get("reason")));
                    if(!"".equals(map1.get("address")) && map1.get("address")!=null){
                        map2.put("khdz", String.valueOf(map1.get("address")));
                    }
                    if(!"".equals(map1.get("contact")) && map1.get("contact")!=null){
                        map2.put("lxrxm", String.valueOf(map1.get("contact")));
                    }
                    if(!"".equals(map1.get("tel")) && map1.get("tel")!=null){
                        map2.put("lxrdh", String.valueOf(map1.get("tel")));
                    }
                    Integer i = dao.getUpdate(map2);
                    if (i <= 0) {
                        throw new RuntimeException("出库订单的修改失败");
                    }
                    throw new SucessException("出库订单的修改成功");
                }
            }else {
                throw new RuntimeException("请选择拆单状态为未拆单的订单数据");
            }
        }else{
            throw new RuntimeException(String.valueOf(map1.get("sono"))+"该订单编号下无相应订单数据，不可执行修改操作!");
        }
    }

    /**
     * 销售出库单取消
     * @param map
     * @throws Exception
     */
    @BaseServiceDescribe(moduleName = "销售出库单取消接口", btnName = "销售出库单取消")
    @Transactional
    public void CancelIssueorder_BD(Map<String,Object> map) throws Exception {
        //取消前查订单主表
        WmsShipmentOrder wmsShipmentOrder = dao.getCdzts(String.valueOf(map.get("sono")));
        //取消前查订单明细表
        List<WmsShipmentOrderDetailed> detailedList = dao.getSeachMx(wmsShipmentOrder.getId());
        if (wmsShipmentOrder != null && detailedList!=null) {
            //订单主表信息里的拆单状态是未拆单
            if (("0").equals(wmsShipmentOrder.getCdzt())) {
                //把查出来的订单主表信息保存的订单主表历史表里
                Integer lg = dao.baseInsertQxFz(wmsShipmentOrder);
                if (lg > 0) {
                    //如果订单主表信息里的拆单状态是未拆单,则可进行取消主表信息
                    Integer i = dao.CancelIssueorder_BD(String.valueOf(map.get("sono")));
                    if(i<=0){
                        throw new RuntimeException("销售出库单取消失败");
                    }
                    for (WmsShipmentOrderDetailed detailed : detailedList) {
                        //把查出来的订单明细表信息保存的订单明细表历史表里
                        Integer alg = dao.baseInsertQxMx(detailed);
                        if (alg > 0) {
                            Integer j = dao.getDeleteMx(wmsShipmentOrder.getId());
                            if (j <= 0) {
                                throw new RuntimeException("销售出库单取消失败");
                            }
                            throw new SucessException("销售出库单取消成功");
                        }
                    }
                }
            }else{
                throw new RuntimeException("请选择订单状态为未拆单的订单数据");
            }
        }else {
            throw new RuntimeException(String.valueOf(map.get("sono"))+"该订单编号下无相应订单数据，不可执行取消操作");
        }
    }
}
